/**************************************************************************************
* TargetPanel.java
* 
*************************************************************************************/
package creid.mythos.ui;

import java.awt.GridLayout;

import javax.swing.JTextField;
import javax.swing.SwingConstants;

import creid.mythos.shared.SpriteMap;

public class TargetPanel extends GamePanel
{

	//Constants/////////////////////////////////////////////////////////////////////////

	private static final long serialVersionUID = -870763905952575241L;
	public static final char HEALTHY_COLOR = 'g';
	public static final char WOUNDED_COLOR = 'y';
	public static final char DYING_COLOR = 'r';
	public static final char FLEE_COLOR = 'P';
	
	static final int WIDTH = GameUI.FONT_HORIZONTAL_SPACING * 20;
	static final int HEIGHT = GameUI.FONT_VERTICAL_SPACING * 5;
	
	//Attributes////////////////////////////////////////////////////////////////////////
	
	private SpriteMap tMap;
	
	private JTextField titleField;
	private JTextField nameField;
	private JTextField healthField;
	
	//Constructors//////////////////////////////////////////////////////////////////////
	
	TargetPanel()
	{
		setSize(WIDTH, HEIGHT);
		
		titleField = super.formattedTextField(SwingConstants.CENTER);
		titleField.setText("    ---Target---    ");
		nameField = super.formattedTextField(SwingConstants.CENTER);
		healthField = super.formattedTextField(SwingConstants.CENTER);
		tMap = null;
		clearTarget();
		setLayout(new GridLayout(3, 1));
		add(titleField);
		add(nameField);
		add(healthField);
	}

	//Methods///////////////////////////////////////////////////////////////////////////
	
	void setMap(SpriteMap map)
	{
		tMap = map;
	}
	
	void clearTarget()
	{
		nameField.setText(SpriteMap.NO_TARGET_NAME);
		healthField.setText(SpriteMap.NO_TARGET_HEALTH);
	}
	
	void updateTarget()
	{
		//titleField.setText("    ---Target---    ");
		if (tMap == null)
		{
			clearTarget();
			return;
		}
		
		nameField.setText(tMap.targetName());
		healthField.setText(tMap.targetHealth());
		healthField.setForeground(GameUI.colors.get(tMap.targetHealthColor()));
	}
}
